<template>
     <div class="good-item">
      <div class="good-img">
        <a @click="openProduct(msg.strId)">
          <img :src="msg.url" :alt="msg.name" >
        </a>
      </div>
      <h6 class="good-title" >{{msg.name}}</h6>
      <div class="good-price pr">
        <div class="ds pa">
          <a @click="openProduct(msg.strId)">
            <button  style="margin: 0 5px" class="grey-btn">查看详情</button>
          </a>
          <button style="margin: 0 5px" 
          @click="addCart" class="main-btn" >加购物车</button>
        </div>
        <p><span style="font-size:14px">￥</span>{{Number(msg.pricePerPeriod).toFixed(2)}}/期</p>
      </div>
     </div>
</template>

<script>
export default {
    props: {
      msg: {
      }
    },
    data () {
      return {  
         cartForm:{
        rentalGoodsId:'',
        userId:'',
        isShoppingCart:true
      }
      }
    },
    methods:{
      openProduct(id){
        window.open('//' + window.location.host+window.location.pathname+ '/#/rentalDetail?Id=' + id)
      },
      async addCart(){
        this.cartForm.rentalGoodsId=this.msg.strId;
        this.cartForm.userId=1;
        const {data:res}=await this.$http.post('rent/RentalFavorite/add',this.cartForm);
        console.log(this.cartForm)
        console.log(res)
        if(res.code==200)
        {
          this.$message.success("添加成功!")
        }
      }
    }
}
</script>

<style lang="less" scoped>
    .good-item {
    background: #fff;
    width: 24%;
    transition: all .5s;
    height: 400px;
    &:hover {
      transform: translateY(-3px);
      box-shadow: 1px 1px 20px #999;
      .good-price p {
        display: none;
      }
      .ds {
        display: flex;
      }
    }
    .ds {
      /*@extend %block-center;*/
      justify-content:center;
      width: 100%;
      display: none;
    }

    .good-img {
      img {
        margin: 50px auto 10px;
        width:206px;
        display: block;
      }
    }
    .main-btn
    {
    width: 100px;
    height: 30px;
    line-height: 28px;
    
    vertical-align: middle;
    background-image: linear-gradient(180deg, #678ee7, #5078df);
    border: 1px solid #5c81e3;
    border-radius: 4px;
    font-size: 12px;
    color:#fff;
    cursor: pointer;
    &:hover {
      background-image: linear-gradient(180deg, #6c8cd4, #4769c2);
    }
    }
    .grey-btn
    {
    width: 100px;
    height: 30px;
    line-height: 28px;
    vertical-align: middle;
    border: 1px solid #e1e1e1;
    border-radius: 4px;
    font-size: 12px;
    color:#646464;
    background-color: #f9f9f9;
    cursor:pointer;
    &:hover{
        background-color: #eee;
    }
    
    }
    .good-price {
      margin: 15px 0;
      height: 30px;
      text-align: center;
      line-height: 30px;
      color: #d44d44;
      font-family: Arial;
      font-size: 18px;
      font-weight: 700;
    }
    .good-title {
      line-height: 1.2;
      font-size: 16px;
      color: #424242;
      margin: 0 auto;
      padding: 0 14px;
      text-align: center;
      overflow: hidden;
    }
    h3 {
      text-align: center;
      line-height: 1.2;
      font-size: 12px;
      color: #d0d0d0;
      padding: 10px;
    }

  }
</style>